<% author_of_work = is_author_of?(work) %>
<% tag_groups = work.tags.group_by { |t| t.type.to_s } %>

<li class="<% if author_of_work %>own <% end %>work blurb" id="work_<%=h work.id %>" role="article">

  <% if !author_of_work && (work.unrevealed? || (work.anonymous? && !@over_anon_threshold && @search)) %>
    <div class="header module mystery">
	    <h4 title="title"><%= ts("Mystery Work") %></h4>
	    <h5><%= h(ts("Part of ")) + work.collections.unrevealed.map {|challenge| link_to(challenge.title, collection_path(challenge))}.join(", ").html_safe %></h5>
	  </div>
	  <h6 class="landmark">Summary</h6>
	  <blockquote class="userstuff summary" title="summary">
		  <p><%= ts("This work is part of an ongoing challenge and will be revealed soon!") %></p>
  	</blockquote>
  <% elsif (@user || @pseud) && work.anonymous? && !author_of_work && !(['gifts', 'readings'].include?(controller.controller_name)) %>
    <div class="header module mystery">
	    <h4 title="title"><%= ts("Mystery Work") %></h4>
	    <h5><%= h(ts("Part of ")) + work.collections.anonymous.map {|challenge| link_to(challenge.title, collection_path(challenge))}.join(", ").html_safe %></h5>
  	</div>
	  <h6 class="landmark">Summary</h6>
	  <blockquote class="userstuff summary" title="summary">
	    <%= ts("This work is part of an ongoing anonymous challenge. You can read the stories in the challenge now, and the authors will be revealed soon.") %>
  	</blockquote>
  <% else %>

    <!--title, author, fandom-->
    <div class="header module">

      <h4 title="title">
  	    <%= link_to work.title, @collection ? collection_work_path(@collection, work) : work %>
   		  <%= ts('by') %>
        
        <!-- do not cache -->
        <%= byline(work) %>

<!-- caching -->
<% cache("#{work.cache_key}-#{hide_warnings?(work) ? 'nowarn' : 'showwarn'}-#{hide_freeform?(work)  ? 'nofreeform' : 'showfreeform'}") do %>

        <% unless work.recipients.blank? %>
          <%= ts("for") %> <%= recipients_link(work) %>
        <% end %>
        <% if work.restricted %><%= image_tag("lockblue.png", :size => "15x15", :alt => "(Restricted)", :title => "Restricted") %><% end %>
        <% if work.hidden_by_admin %><%= image_tag("lockred.png", :size => "15x15", :alt => "(Hidden by Admin)", :title => "Hidden by Administrator") %><% end %>
      </h4>

  	  <h5 title="fandom">
        <% fandoms = tag_groups['Fandom'] %>
        <%= fandoms.collect{|tag| link_to_tag(tag) }.join(', ').html_safe if fandoms %>
  		  &nbsp;
  	  </h5>

      <!--required tags-->
  	  <%= get_symbols_for(work, tag_groups) %>
  	  <p class="datetime"><%= set_format_for_date(work.revised_at) %></p>
    </div>
	  
	  <!-- do not cache -->
    <!--warnings again, cast, freeform tags-->
  	<h6 class="landmark">Tags</h6>
  	<ul class="tags">
  	  <%= blurb_tag_block(work, tag_groups) %>
  	</ul>

    <!--summary-->	
  	<% unless work.summary.blank? %>
  		<h6 class="landmark">Summary</h6>
  		<blockquote class="userstuff summary" title="summary">
  		  <%=raw strip_images(sanitize_field(work, :summary)) %>
  		</blockquote>
  	<% end %>

    <!--stats-->
  	<dl class="stats" title="stats">
  		<dt><%= ts('Words') %>:</dt>
  		<dd><%= number_with_delimiter(work.word_count) %></dd>
  		<dt><%= ts('Chapters') %>:</dt>
  		<dd><%= work.chapter_total_display %></dd>

<% end %>
<!-- end cached section -->
	 
  	  <% unless work.approved_collections.empty? %>
  			<dt><%= ts('Collections')  %>:</dt>
  			<dd><%= link_to work.approved_collections.length, work_collections_path(work) %></dd>
  		<% end %>
		
  		<% if work.count_visible_comments > 0 %>
  		  <dt><%= ts('Comments') %>:</dt>
  			<dd><%= link_to work.count_visible_comments, 
  			            @collection ? collection_work_path(@collection, work, :anchor => "comments", :show_comments => true) : 
  			                (work.chapter_total_display.to_i > 1 ? work_path(work, :anchor => "comments", :show_comments => true, :view_full_work => 'true') : work_path(work, :anchor => "comments", :show_comments => true)) %></dd>
  		<% end %>
  		<% if work.kudos.count > 0 %>
  		  <dt><%= ts('Kudos: ') %></dt>
  		  <dd><%= link_to (work.kudos.by_guest.count(:ip_address, :distinct => true) + work.kudos.with_pseud.count(:pseud_id, :distinct => true)).to_s, 
  		      @collection ? collection_work_path(@collection, work, :anchor => "comments") : 
              (work.chapter_total_display.to_i > 1 ? work_path(work, :anchor => "comments", :view_full_work => 'true') : 
                work_path(work, :anchor => "comments")) %></dd>
  		<% end %>
  		<% if (bookmark_count = work.bookmarks.is_public.count) > 0 %>
  		  <dt><%= ts('Bookmarks') %>:</dt>
  			<dd><%= link_to_bookmarkable_bookmarks(work, bookmark_count.to_s) %></dd>
  		<% end %>

    	<% if show_hit_count?(work) %>
     		<dt><%= ts("Hits") %>:</dt>
     		<dd><%= work.hits %></dd>
     	<% end %>
			
    </dl>

    <% if author_of_work %>
      <h6 class="landmark">Author Actions</h6>
  	  <ul class="navigation" role="navigation">
            <li><%= link_to ts('Edit'), edit_work_path(work) %></li>
  	    <li><%= link_to ts("Edit Tags"), edit_tags_work_path(work) %></li> 
        <% if work.is_wip %>
          <li><%= link_to ts('Add Chapter'), new_work_chapter_path(work) %></li>
        <% end %>
        <% if !work.posted? %>
          <li><%= link_to ts('Post Draft'), post_draft_work_path(work), :method => :put %></li>
          <li><%= link_to ts("Delete Draft"), work, :confirm => "Are you sure?", :method => :delete %></li>
        <% end %>
      </ul>
    <% end %>

  <% end %>
</li>
